package com.ruoyi.project.beautyflower.paymentHistory.controller;

import java.util.List;

import com.ruoyi.project.beautyflower.order.domain.Order;
import com.ruoyi.project.beautyflower.order.service.IOrderService;
import com.ruoyi.project.beautyflower.repaymentPlan.domain.RepaymentPlan;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.beautyflower.paymentHistory.domain.PaymentHistory;
import com.ruoyi.project.beautyflower.paymentHistory.service.IPaymentHistoryService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 还款记录 信息操作处理
 *
 * @author lxs
 * @date 2018-10-18
 */
@Controller
@RequestMapping("/beautyflower/paymentHistory")
public class PaymentHistoryController extends BaseController {
    private String prefix = "beautyflower/paymentHistory";

    @Autowired
    private IPaymentHistoryService paymentHistoryService;
    @Autowired
    private IOrderService orderService;

    @RequiresPermissions("beautyflower:paymentHistory:view")
    @GetMapping()
    public String paymentHistory() {
        return prefix + "/paymentHistory";
    }

    /**
     * 查询还款记录列表
     */
    @RequiresPermissions("beautyflower:paymentHistory:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PaymentHistory paymentHistory) {
        startPage();
        List<PaymentHistory> list = paymentHistoryService.selectPaymentHistoryList(paymentHistory);
        return getDataTable(list);
    }

    /**
     * 新增还款记录
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存还款记录
     */
    @RequiresPermissions("beautyflower:paymentHistory:add")
    @Log(title = "还款记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PaymentHistory paymentHistory) {
        return toAjax(paymentHistoryService.insertPaymentHistory(paymentHistory));
    }

    /**
     * 修改还款记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        PaymentHistory paymentHistory = paymentHistoryService.selectPaymentHistoryById(id);
        mmap.put("paymentHistory", paymentHistory);
        return prefix + "/edit";
    }

    /**
     * 修改保存还款记录
     */
    @RequiresPermissions("beautyflower:paymentHistory:edit")
    @Log(title = "还款记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PaymentHistory paymentHistory) {
        return toAjax(paymentHistoryService.updatePaymentHistory(paymentHistory));
    }

    /**
     * 删除还款记录
     */
    @RequiresPermissions("beautyflower:paymentHistory:remove")
    @Log(title = "还款记录", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(paymentHistoryService.deletePaymentHistoryByIds(ids));
    }

    /**
     * 修改订单
     */
    @GetMapping("/paymentdetails/{id}")
    public String paymentDetails(@PathVariable("id") Integer id, ModelMap mmap) {
        // 查询还款记录
        PaymentHistory paymentHistory = paymentHistoryService.selectPaymentHistoryById(id);
        mmap.put("paymentHistory", paymentHistory);
        // 查询还款订单
        Order order = orderService.selectOrderByListOrderNumber(paymentHistory.getOrderId());
        mmap.put("order", order);
        return prefix + "/paymentdetails";
    }
}
